<?php
/* Kammerath Network Website System - Analytics */
require_once("../config.php");

// internal libraries
require_once("../class/cache.class.php");
require_once("../class/facebook.class.php");
require_once("../class/database.class.php");

// external libraries
require_once("../lib/Smarty/Smarty.class.php");

// instance the facebook class
$f = new facebook();

// check if the user is logged in
if($f->isLoggedIn()){
	// get the logged in user
	$user = $f->getUser();
	
	// instanciate the db class
	$db = new database();
	
	// analytics is only available to admin users
	if($db->userIsAdmin($user->username)){
		// instanciate the template system
		$template = new Smarty();
		$template->assign("report",simplexml_load_file
				(CONFIG_ROOTDIR."/analytics/data/report.xml"));	
		
		// display the template
		$template->display("../themes/analytics/index.tpl");
	}else{
		// display an error message
		echo("Administrator privileges required for analytics.");	
	}
}else{
	// display an error message
	echo("Authentication required for analytics.");	
}
?>